package fishinpool;

import static fishinpool.Direction.DOWNLEFT;
import static fishinpool.Direction.RIGHT;
import static fishinpool.Direction.UPLEFT;

public class Position {
    public int width;
    public int length;
    private int x;
    private int y;
    private Area workArea;
       public Position(int x, int y, Area workArea) {
        if (x < workArea.getWidth()) {
            this.x = x;
        }
        if (y < workArea.getLength()) {
            this.y = y;
        }
        this.workArea = workArea;
    }
    public Position(Area workArea) {
        x = Random.getRandomNum(workArea.getWidth());
        y = Random.getRandomNum(workArea.getLength());
        this.workArea = workArea;
    }
    public boolean equals(Position position) {
        return x == position.x && y == position.y && workArea == position.workArea;
    }

    public void changePosition(Direction direction, int step) {
        switch (direction) {
            case RIGHT:
                if (this.x + step <= workArea.getLength()) {
                    x += step;
                }
                break;
            case UPRIGHT:
                if (this.x + step <= workArea.getLength() && this.y + step <= workArea.getWidth()){
                    
                }
                break;       
            case UPLEFT:
                if (this.x - step >= 0 && this.y + step >=0) {
                    x -= step;
                    y +=step;
                }
                break;
            case LEFT:
                if (this.x - step >= 0) {
                    x -= step;
                }
                break;

            case DOWNLEFT:
                if (this.y - step <= workArea.getWidth() && this.x - step >= workArea.getLength()) {
                    y -= step;
                    x -= step;
                }
                break;
            case DOWNRIGHT:
                if (this.y - step <= workArea.getWidth() && this.x + step <= workArea.getLength()) {
                    y -= step;
                    x += step;
                }
                break;
            
            default:
                break;
        }
    }
    public int getX() {        
        return x;    
    }
    public int getY() {        
        return y;    
    }
    private Area getworkArea() {
        return workArea;
    }
    public String toString() {
        return String.format("%d, %d", this.x, this.y);
    }

    Area getWorkArea() {
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    }

    public int getWidth() {
        return width;
     }
    public int getLength() {
        return length;
    }
}
